﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;

namespace Newtonsoft.Json.ConsoleApp
{
    class Program
    {
        public class Test
        {
            public string t1;
            public string t2;
            private string t3;
            private int t4 { get; set; }
            protected int t5 { get; set; }
            public int MyProperty { get; set; }
        }
        static void Main(string[] args)
        {

            JObject o = JObject.Parse(@"{""Stores"": [
    ""Lambton Quay"",
    ""Willis Street""
  ],
  ""Manufacturers"": [
    {
      ""Name"": ""Acme Co"",
      ""Products"": [
        {
          ""Name"": ""Anvil"",
          ""Price"": 50
        }
      ]
    },
    {
      ""Name"": ""Contoso"",
      ""Products"": [
        {
          ""Name"": ""Elbow Grease"",
          ""Price"": 99.95
        },
        {
          ""Name"": ""Headlight Fluid"",
          ""Price"": 4
        }
      ]
    }
  ]
}");
            string str = "{\"_id\":\"2324\"}";
            WriterInfo tt1 = JsonConvert.DeserializeObject<WriterInfo>(str);
         
            Console.Read();

        }
    }

    public class FieldNameContractResolver : DefaultContractResolver
    {
        private static readonly Dictionary<string, string> FieldNameComparionTable = new Dictionary<string, string>(5);

        public FieldNameContractResolver()
            : base(true)
        {
        }

        static FieldNameContractResolver()
        {
            FieldNameComparionTable.Add("Id", "_id");
            FieldNameComparionTable.Add("Name", "writer");
            //FieldNameComparionTable.Add("name", "organ");
            //FieldNameComparionTable.Add("name", "subject");
            //FieldNameComparionTable.Add("name", "media");
            //FieldNameComparionTable.Add("name", "classtypename");
            //FieldNameComparionTable.Add("name", "fund");
            FieldNameComparionTable.Add("Medias", "medias_by");
            FieldNameComparionTable.Add("Classnum", "class");
        }
        protected override string ResolvePropertyName(string propertyName)
        {
            if (FieldNameComparionTable.ContainsKey(propertyName))
                return FieldNameComparionTable[propertyName];
            return propertyName;
        }
    }
    public class WriterInfo
    {
        [JsonProperty(PropertyName = "_id")]
        public string Id { get; set; }
        public string Name { get; set; }
        public string OrganId { get; set; }
        public string Organ { get; set; }

    }
}
